package my.study.springcloud.eurekaclient;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.discovery.DiscoveryClient;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrix
@EnableCircuitBreaker
@RestController
public class EurekaClient 
{
	
	@Autowired
    @Qualifier("helloClient")
    HelloClient client;

    @Autowired
    @Qualifier("hystrixHelloClient")
    HelloClient hytrixClient;
    
   
    @Autowired
    private DiscoveryClient discoveryClient;
    
    @RequestMapping("/")
    public String hello() {
    	System.out.println(1);
        return client.hello();
    }

    /**
     * 1、调用hytrix
     * 2、hytrix继承并调用feign
     * 3、feign会去调用eurekaService
     * */
    @RequestMapping("/hytrix")
    public String hytrixHello() {
        return hytrixClient.hello();
    }
    
    @ResponseBody
    @RequestMapping(name="/client/test",method={RequestMethod.POST,RequestMethod.GET})
    public Object test(@RequestBody Map<String,Object> aa){
    	System.out.println();
    	return aa;
    }

	 public static void main(String[] args) {
	        SpringApplication.run(EurekaClient.class, args);
	 }
}
